package com.example.controller;

import com.example.common.Result;
import com.example.entity.ZyzActivityType;
import com.example.service.ZyzActivityTypeService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 活动类型
 */
@RestController
@RequestMapping("/api/zyzActivityType")
public class ZyzActivityTypeController {
    @Autowired
    private ZyzActivityTypeService zyzActivityTypeService;

    /**
     * 添加
     */
    @PostMapping("/add")
    public Result add(@RequestBody ZyzActivityType zyzActivityType) {
        zyzActivityTypeService.add(zyzActivityType);
        return Result.success();
    }

    /**
     * 删除
     */
    @PostMapping("/delete/batch")
    public Result deleteBatch( String ids) {
        zyzActivityTypeService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public Result update(@RequestBody ZyzActivityType zyzActivityType) {
        zyzActivityTypeService.updateById(zyzActivityType);
        return Result.success();
    }

    /**
     * 根据id查询
     */
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id) {
        ZyzActivityType zyzActivityType = zyzActivityTypeService.selectById(id);
        return Result.success(zyzActivityType);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(ZyzActivityType zyzActivityType) {
        List<ZyzActivityType> list =zyzActivityTypeService.selectAll(zyzActivityType);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(ZyzActivityType zyzActivityType,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<ZyzActivityType> page = zyzActivityTypeService.selectPage(zyzActivityType, pageNum, pageSize);
        return Result.success(page);
    }

}
